<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>"><!-- jsp文件头和头部 -->
	<%@ include file="../../system/admin/top.jsp"%> 
	</head>
<body>
			<!-- 检索  -->
			<form action="company/list.do" method="post" name="Form" id="Form">
			        <div class="con-form" >
					     <input autocomplete="off" id="nav-search-input" type="text" name="keyWord" value="${pd.keyWord}" placeholder="这里输入关键词" />
					     <button class="search" onclick="search();"  title="查询">查询</button>
					</div>
					<p class="operate">
		                  <a class="create Operate" title="新增"  onclick=" add()">新增</a>
		                  <a class="delete" onclick="makeAll();" title="批量删除">批量删除</a>
		             </p>
             
			<!-- 检索  -->
		
			<table >
				    <colgroup>
		            <col width="2%">
		            <col width="2%">
		            <col width="8%">
		            <col width="5%">
		            <col width="6%">
		            <col width="5%">
		            <col width="6%">
		            <col width="13%">
		            <col width="6%">
		        </colgroup>
				<thead>
					<tr>
						<th>
						<input type="checkbox" id="zcheckbox" />
						</th>
						<th>序号</th>
						<th>公司名称</th>
						<th>联系方式</th>
						<th>email</th>
						<th>网址</th>
						<th>创建时间</th>
						<th>地址</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
				<!-- 开始循环 -->	
				<c:choose>
					<c:when test="${not empty varList}">
						<c:if test="${QX.cha == 1 }">
						<c:forEach items="${varList}" var="var" varStatus="vs">
							<tr>
										<td>
										<input type='checkbox' name='ids' value="${var.company_id}" />
										</td>
								        <td>${vs.index+1}</td>
										<td>${var.company_name}</td>
										<td>${var.company_phone}</td>
										<td>${var.company_email}</td>
										<td>${var.company_url}</td>
										<td><fmt:formatDate value="${var.create_date}" pattern="yyyy-MM-dd"/></td>
										<td>${var.company_address}</td>
										 <td>
										 <p class="operate">
												<c:if test="${QX.edit != 1 && QX.del != 1 }">
												    <div class="operate-more">
			                                           <span class='operate-false'></span>
		                    	                    </div>
												</c:if>
													<c:if test="${QX.edit == 1 }">
													<a  title="编辑"  onclick="edit('${var.company_id}');" class="operatea revise">编辑</a>
													</c:if>
													<c:if test="${QX.del == 1 }">
													<a title="删除" onclick="del('${var.company_id}');" class="operatea delete" >删除</a>
													</c:if>
											</p>
										</td>
							</tr>
						</c:forEach>
						</c:if>
						<c:if test="${QX.cha == 0 }">
							<tr>
								<td colspan="100" class="center">您无权查看</td>
							</tr>
						</c:if>
					</c:when>
					<c:otherwise>
						<tr class="main_info">
							<td colspan="100" class="center" >没有相关数据</td>
						</tr>
					</c:otherwise>
				</c:choose>
				</tbody>
			</table>
			<div class="branchPage">${page.pageStr}</div>
		</form>
		<!-- 引入 -->
       <script type="text/javascript">		
		//检索
		function search(){
			$("#Form").submit();
		}
		
		//新增
		function add(){
			$("#zhongxin",domObj).show();
			$("#zhongxin iframe",domObj).attr("src","<%=basePath%>company/goAdd.do");
		}
		
		//删除
		function del(Id){
			$.confirm('你确定要删除这条消息吗? ',null,function(type){
		        if(type==='yes'){
					var url = "<%=basePath%>company/delete.do?company_id="+Id+"&tm="+new Date().getTime();
					$.get(url,function(data){
							if(data == "success"){
								alert("删除成功");
								//刷新页面
								location.href="<%=basePath%>company/list.do";
							}
					});
		        }else{
		        	//do Nothing
		        }
		        this.hide();
			 });
		}
		//修改
		function edit(Id){
			$("#zhongxin",domObj).show();
			$("#zhongxin iframe",domObj).attr("src","<%=basePath%>company/goEdit.do?company_id="+Id);
		}
		
		$(function() {
				//下拉框
				$(".chzn-select").chosen(); 
				$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
				//日期框
				$('.date-picker').datepicker();
			
			//复选框
			$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
			});
		});
	
				//批量操作
			function makeAll(){
			var str = '';
			for(var i=0;i < document.getElementsByName('ids').length;i++){
				  if(document.getElementsByName('ids')[i].checked){
				  	if(str==''){
				  		str += document.getElementsByName('ids')[i].value;
				  	}else{
				  		str += ',' + document.getElementsByName('ids')[i].value;
				  	}
				  }
			}
			if(str==''){
				$("#zcheckbox").tips({
					side:1,
		            msg:'点这里全选',
		            bg:'#AE81FF',
		            time:8
		        });
				return;
			}
			$.confirm('你确定要删除这条消息吗? ',null,function(type){
		        if(type==='yes'){
		        	$.ajax({
		    			type: "POST",
		    			url: '<%=basePath%>company/deleteAll.do?tm='+new Date().getTime(),
		    	    	data: {DATA_IDS:str},
		    			dataType:'json',
		    			cache: false,
		    			success: function(data){
		    				//刷新列表页面
		    				location.href='<%=basePath%>company/list.do';
		    			}
		    		});
		        }else{
		           //do Nothing
		        }
		        this.hide();
		    });
		}
		</script>
	</body>
</html>

